<template>
    <div>
        <div class="tab-back">
            <span @click="toback()" class="left"></span>
            <div class="title">主页设置</div><div class="right"></div>
        </div>
        <div :class="homestatus==1?'my-data-set-up active':'my-data-set-up'">
            <div class="box-r4">
                <p class="p1" v-if="homestatus==1">个人主页<span>（已开启）</span></p>
                <p class="p7" v-else>个人主页<span>（已关闭）</span></p>
                <p class="p2" @click="setup()"></p>
            </div>
            <p class="p3">相关设置</p>
            <div class="box-r4 p4">
                <p class="p5"><span class="s1">主页在售料显示</span><span class="s2">选择后客户只能看到您最近发布的料</span></p>
                <select dir="rtl" v-model="materialsnumber">
                    <option value="1000">展示全部</option>
                    <option value="0">0个</option>
                    <option value="1">1个</option>
                    <option value="2">2个</option>
                    <option value="3">3个</option>
                    <option value="4">4个</option>
                    <option value="5">5个</option>
                    <option value="6">6个</option>
                    <option value="7">7个</option>
                    <option value="8">8个</option>
                    <option value="9">9个</option>
                    <option value="10">10个</option>
                    <option value="20">20个</option>
                    <option value="30">30个</option>
                    <option value="40">40个</option>
                    <option value="50">50个</option>
                    <option value="100">100个</option>
                    <option value="200">200个</option>
                </select>
            </div>
            <div class="box-r4 p4">
                <p class="p5"><span class="s1">在售料展示（时间）</span><span class="s2">展示所设置时间段内的料</span></p>
                <select dir="rtl" v-model="materialsshowtime">
                    <option value="1000">全部</option>
                    <option value="0">0小时</option>
                    <option value="6">6小时内</option>
                    <option value="12">12小时内</option>
                    <option value="24">24小时内</option>
                    <option value="48">48小时内</option>
                    <option value="72">72小时内</option>
                </select>
            </div>
            <div class="box-r4 p6">
                <div class="tips_title">主页个性签名</div>
                <textarea class="add-tarea-input" placeholder="20个字以内哦～" v-model="bio" maxlength="20"></textarea>
            </div>
            <input type="button" class="btn" value="保存" @click="submit()">
        </div>
    </div>
</template>

<script>
    export default {
        name: "",
        data(){
            return {
                homestatus:"",
                materialsnumber:"",
                materialsshowtime:"",
                bio:""
            }
        },
        mounted(){
            this.getMsg();
        },
        methods:{
            toback(){
                this.$router.go(-1);//返回上一层
            },
            submit(){
                var that=this;
                that.request1.post1({
                    url: that.Url + "api/user.index/profile",
                    params: {
                        homestatus:that.homestatus,
                        materialsnumber:that.materialsnumber,
                        materialsshowtime:that.materialsshowtime,
                        bio:that.bio
                    },
                    success: function (res) {
                        if (res.data.code == 1) {
                            that.$toast.success("修改成功");
                        } else {
                            alert(res.data.msg)
                        }
                    },
                    fail: function (error) {
                        alert(error.data.msg)
                    }
                })
            },
            //开关
            setup(){
              this.homestatus=this.homestatus==1?0:1;
            },
            getMsg(){
                var that=this;
                that.request1.post1({
                    url: that.Url + "api/user.index/homeSetting",
                    params: {},
                    success: function (res) {
                        console.log(res)
                        if (res.data.code == 1) {
                            that.homestatus=res.data.data.homestatus;
                            that.materialsnumber=res.data.data.materialsnumber;
                            that.materialsshowtime=res.data.data.materialsshowtime;
                            that.bio=res.data.data.bio;
                        } else {
                            alert(res.data.msg)
                        }
                    },
                    fail: function (error) {
                        alert(error.data.msg)
                    }
                })
            }
        }
    }
</script>

<style scoped>
    >>> body{

    }
    .tab-back {
        height: 44px;
        background: #fc5d4d;
        display: -webkit-box;
    }
    .tab-back .left {
        width: 44px;
        display: block;
        height: 44px;
        background: url() no-repeat 50%;
        background-size: 9px 16px;
    }
    .tab-back .title {
        -webkit-box-flex: 1;
        font-size: 15px;
        color: #fff;
        font-weight: 700;
        text-align: center;
        line-height: 44px;
    }
    .tab-back .right {
        width: 44px;
        height: 44px;
    }
    .my-data-set-up {
        height: 62px;
        overflow: hidden;
    }
    .my-data-set-up.active {
        display: block;
        height: auto;
        overflow: inherit;
    }
    .box-r4, .red_btn {
        border-radius: 4px;
    }
    .box-r4 {
        display: block;
        background: #fff;
        margin: 7px 10px 0;
        padding: 0 15px;
        overflow: hidden;
        font-size: 14px;
    }
    .my-data-set-up .p1, .my-data-set-up .p7 {
        height: 55px;
        line-height: 55px;
        font-weight: 700;
        float: left;
    }
    .my-data-set-up.active .p1 {
        display: block;
        height: 55px;
        line-height: 55px;
        font-weight: 700;
        float: left;
    }
    .my-data-set-up.active .p1 span {
        color: #ff6e6e;
        font-weight: 400;
        font-size: 12px;
        height: 55px;
    }
    .my-data-set-up.active .p7 {
        display: none;
    }
    .my-data-set-up .p7 span {
        color: #999;
        font-weight: 400;
        font-size: 12px;
        height: 55px;
    }
    .my-data-set-up .p2 {
        display: block;
        width: 37px;
        height: 55px;
        float: right;
        background: url() 50% no-repeat;
        background-size: 37px 21px;
    }
    .my-data-set-up.active .p2 {
        display: block;
        width: 37px;
        height: 55px;
        float: right;
        background: url() 50% no-repeat;
        background-size: 37px 21px;
    }
    .my-data-set-up.active .p3 {
        padding-left: 15px;
        color: #999;
        font-weight: 700;
        line-height: 12px;
        padding-top: 30px;
        font-size: 12px;
        margin-bottom: 10px;
    }
    .my-data-set-up.active .p4 {
        padding-top: 10px;
        padding-bottom: 10px;
        display: -webkit-box;
    }
    .my-data-set-up.active .p4 .p5 {
        -webkit-box-flex: 1;
    }
    .my-data-set-up.active .p4 .p5 span {
        display: block;
    }
    .my-data-set-up.active .p4 .p5 span.s1 {
        font-size: 14px;
        font-weight: 700;
        line-height: 24px;
    }
    .my-data-set-up.active .p4 .p5 span.s2 {
        font-size: 12px;
        color: #999;
        line-height: 18px;
    }
    .my-data-set-up.active .p4 select {
        width: 90px;
        height: 32px;
        display: block;
        padding-right: 10px;
        margin-top: 5px;
        margin-left: 10px;
        border: 1px solid #b9b9b9;
        background: url() no-repeat 10px;
        background-size: 10px;
        font-size: 12px;
        appearance: none;
        -moz-appearance: none;
        -webkit-appearance: none;
        -ms-appearance: none;
    }
    .my-data-set-up.active .p6 {
        padding-bottom: 15px;
        margin-top: 10px;
    }
    .tips_title {
        font-size: 14px;
        font-weight: 700;
        color: #000;
        display: block;
        line-height: 14px;
        padding-top: 20px;
        padding-bottom: 10px;
    }
    .box-r4 .add-tarea-input {
        letter-spacing: .2px;
        display: block;
        padding: 10px 4%;
        width: 92%;
        background: #f9f9fb;
        min-height: 60px;
        line-height: 20px;
        font-size: 13px;
        border-radius: 4px;
        border: 1px solid #e5e5e5;
    }
    .my-data-set-up.active .btn {
        display: block;
        -webkit-box-flex: 1;
        background: #fc5d4d;
        color: #fff;
        font-size: 14px;
        text-align: center;
        height: 40px;
        line-height: 40px;
        border-radius: 4px;
        box-shadow: 0 5px 10px #f6a59f;
        width: 90%;
        margin: 30px 5%;
    }
</style>